package tt.dz.egobus.servicemanager.vo;

import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import tt.dz.egobus.api.AbstractRequestParameter;
import tt.dz.egobus.api.managerservice.manager.BusinessDetail;
import tt.dz.egobus.bean.BaseBean;

import java.util.Date;

/**
 * @author Anson
 * @date 17-3-29
 * @name 业务完成的请求vo
 * @since 1.0.3
 */
public class BusinessFinishVo extends AbstractRequestParameter implements BaseBean {

    private static final Logger LOGGER = LoggerFactory.getLogger(BusinessFinishVo.class);

    private static final long serialVersionUID = -745289870319567268L;
    /**
     * 司机id
     */
    private String driverId;

    /**
     * 用户id
     */
    private String userId;

    /**
     * 用户手机号码
     */
    private String userMobile;

    /**
     * 业务流水号
     */
    private String businessId;

    /**
     * 结束地点经度坐标
     */
    private double x;
    /**
     * 结束地点纬度坐标
     */
    private double y;

    /**
     * 结束的地理位置名称
     */
    private String address;

    /**
     * 结束的第三方计算出来的里程距离(单位m,米)
     */
    private double distance;

    /**
     * 司机端计算里程距离(单位m,米)
     * 用于计算里程数有效性
     *
     * @since 1.0.3
     */
    private double driverAccDistance;


    private double realDistance;

    private Date endTime;


    /**
     * @param detail 业务完成时候的bean
     * @author Anson
     * @date 17-3-29
     * @name
     * @since 1.0.3
     */
    public static final BusinessFinishVo copy(BusinessDetail detail) {
        BusinessFinishVo vo = new BusinessFinishVo();
        try {
            BeanUtils.copyProperties(detail, vo);
        } catch (RuntimeException e) {
            LOGGER.error("业务完成接单任务时服务层Vo的bean转换异常", e);
        }
        return vo;
    }

    /**
     * @author Anson
     * @date 17-3-29
     * @name 获取真正的距离
     * @since 1.0.3
     */
    public double getRealDistance() {
        return this.realDistance;
    }

    @Override
    public boolean validate() {
        return !(StringUtils.isEmpty(this.driverId) || StringUtils.isEmpty(this.userId)
                || StringUtils.isEmpty(this.userMobile) || StringUtils.isEmpty(this.businessId)
                || x < 0 || x > 360 || y < 0 || y > 180 || StringUtils.isEmpty(this.address)
                || distance < 0 || driverAccDistance < 0 || this.endTime == null);
    }

    public String getDriverId() {
        return driverId;
    }

    public void setDriverId(String driverId) {
        this.driverId = driverId;
    }

    public String getUserId() {
        return userId;
    }

    public void setUserId(String userId) {
        this.userId = userId;
    }

    public String getUserMobile() {
        return userMobile;
    }

    public void setUserMobile(String userMobile) {
        this.userMobile = userMobile;
    }

    public String getBusinessId() {
        return businessId;
    }

    public void setBusinessId(String businessId) {
        this.businessId = businessId;
    }

    public double getX() {
        return x;
    }

    public void setX(double x) {
        this.x = x;
    }

    public double getY() {
        return y;
    }

    public void setY(double y) {
        this.y = y;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public double getDistance() {
        return distance;
    }

    public void setDistance(double distance) {
        this.distance = distance;
    }

    public double getDriverAccDistance() {
        return driverAccDistance;
    }

    public void setDriverAccDistance(double driverAccDistance) {
        this.driverAccDistance = driverAccDistance;
    }


    public void setRealDistance(double realDistance) {
        this.realDistance = realDistance;
    }

    public Date getEndTime() {
        return endTime;
    }

    public void setEndTime(Date endTime) {
        this.endTime = endTime;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof BusinessFinishVo)) return false;

        BusinessFinishVo that = (BusinessFinishVo) o;

        if (Double.compare(that.getX(), getX()) != 0) return false;
        if (Double.compare(that.getY(), getY()) != 0) return false;
        if (Double.compare(that.getDistance(), getDistance()) != 0) return false;
        if (Double.compare(that.getDriverAccDistance(), getDriverAccDistance()) != 0) return false;
        if (Double.compare(that.getRealDistance(), getRealDistance()) != 0) return false;
        if (getDriverId() != null ? !getDriverId().equals(that.getDriverId()) : that.getDriverId() != null)
            return false;
        if (getUserId() != null ? !getUserId().equals(that.getUserId()) : that.getUserId() != null) return false;
        if (getUserMobile() != null ? !getUserMobile().equals(that.getUserMobile()) : that.getUserMobile() != null)
            return false;
        if (getBusinessId() != null ? !getBusinessId().equals(that.getBusinessId()) : that.getBusinessId() != null)
            return false;
        if (getAddress() != null ? !getAddress().equals(that.getAddress()) : that.getAddress() != null) return false;
        return getEndTime() != null ? getEndTime().equals(that.getEndTime()) : that.getEndTime() == null;

    }

    @Override
    public int hashCode() {
        int result;
        long temp;
        result = getDriverId() != null ? getDriverId().hashCode() : 0;
        result = 31 * result + (getUserId() != null ? getUserId().hashCode() : 0);
        result = 31 * result + (getUserMobile() != null ? getUserMobile().hashCode() : 0);
        result = 31 * result + (getBusinessId() != null ? getBusinessId().hashCode() : 0);
        temp = Double.doubleToLongBits(getX());
        result = 31 * result + (int) (temp ^ (temp >>> 32));
        temp = Double.doubleToLongBits(getY());
        result = 31 * result + (int) (temp ^ (temp >>> 32));
        result = 31 * result + (getAddress() != null ? getAddress().hashCode() : 0);
        temp = Double.doubleToLongBits(getDistance());
        result = 31 * result + (int) (temp ^ (temp >>> 32));
        temp = Double.doubleToLongBits(getDriverAccDistance());
        result = 31 * result + (int) (temp ^ (temp >>> 32));
        temp = Double.doubleToLongBits(getRealDistance());
        result = 31 * result + (int) (temp ^ (temp >>> 32));
        result = 31 * result + (getEndTime() != null ? getEndTime().hashCode() : 0);
        return result;
    }

    @Override
    public String toString() {
        return "BusinessFinishVo{" +
                "driverId='" + driverId + '\'' +
                ", userId='" + userId + '\'' +
                ", userMobile='" + userMobile + '\'' +
                ", businessId='" + businessId + '\'' +
                ", x=" + x +
                ", y=" + y +
                ", address='" + address + '\'' +
                ", distance=" + distance +
                ", driverAccDistance=" + driverAccDistance +
                ", realDistance=" + realDistance +
                ", endTime=" + endTime +
                '}';
    }
}
